<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>父子组件事件通信</title>
    <style>
      * {
        user-select: none;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>

    <div id="root"></div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            count: 0,
          };
        },

        template: `
                 <counter v-model:add="count"/>
                `,
      });

      app.component("counter", {
        props: ["add"],
        methods: {
          handleClick() {
            this.$emit("update:add", this.add + 2);
          },
        },

        template: `<div @click="handleClick">{{add}}</div>`,
      });

      const vm = app.mount("#root");
    </script>
  </body>
</html>
